package com.jlc.book.shop.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jlc.book.shop.delegate.UserDelegate;
import com.jlc.book.shop.validator.JLCDataValidator;

public class ForgetPasswordAction {
	public String searchPassword(HttpServletRequest req,HttpServletResponse res){
		String page="forgetPasswordDef.jsp";
		String uname=req.getParameter("uname");
		String email=req.getParameter("email");
		boolean intactWithDB=true;
		if(!JLCDataValidator.validateRequired(uname)){
			req.setAttribute("uname","Username is required");
			intactWithDB=false;
		}
		if(!JLCDataValidator.validateRequired(email)){
			req.setAttribute("email","Email is required");
			intactWithDB=false;
		}else if(!JLCDataValidator.validateRequired(uname)){
			req.setAttribute("email","Please enter valid email id");
			intactWithDB=false;
		}
		if(intactWithDB){
			String password=UserDelegate.searchPassword(uname,email);
			if(password!=null){
				req.setAttribute("PASSWORD",password);
			}else{
				req.setAttribute("forgetPasswordError","Provided information is invalid");
			}
		}
		return page;
	}
}
